<?php
// 系统默认控制器
class AppointmentAction extends SaleAction
{
    public function index()
    {
        $pagenum = I("get.p");
        $username = I("session.userid");

        $empids = $this->getMyEmployee();
        $condition['adduser'] = array('in', $empids);

       // $condition['adduser'] = $username;
        $condition['apptime'] = array('egt', date("Y-m-d"));
        $data=$this->getPageData('AppointView',$pagenum,$condition);

        $tempEmployees= $this-> getMyEmployee(0);
        foreach ($tempEmployees as $k => $v)
            $employees[$v["id"]] = $v;
        $this->employees=$employees;

        $this->assign('accounts_list',$data["list"]); // 数据列表变量赋值
        $this->assign('page_method', $data['pageshow']); //分页列表变量赋值
        $this->display(); // 输出模板
    }

    public function newitem()
    {
        $custom = M('Custom');
        $id = $_GET['id'];
        $custom_item = $custom->where("id=$id")->find();
        //dump($custom_item);
        $this->assign('id', $custom_item["id"]);
        $this->assign('cname', $custom_item["cname"]);
        $this->assign('company', $custom_item["company"]);
        $this->display();
    }

    public function itemsave()
    {

        $username = I("session.userid");
        $newitem = D('appointment'); // 实例化模型类
        $data = $newitem->create();
        if ($data)
        {
            $data["addtime"] = date('Y-m-d H:i:s');
            $data["adduser"] = $username;
            $newitem->add($data);

            //$newitem->getLastSql();
            //$this->show('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script><script type="text/javascript">$(function(){top.Dialog.alert("成功提交",function(){window.parent.frmright.location.href("/index.php/Appointment/");top.Dialog.close()})})</script>','utf-8');
            $this->success('成功提交');
        } else
        {

            //  $this->error($newitem->getError());
            echo '信息添加失败，请检查网络！';
        }
    }

    public function additem()
    {
        $custom = M('Appointment');
        $id = $_GET['id'];
        $custom_item = $custom->where("id=$id")->find();
        $this->assign('id', $custom_item["id"]);
        $this->assign('content', $custom_item["content"]);
        $this->assign('apptime', $custom_item["apptime"]);

        $customt = M('Custom');
        $customid = $_GET['customid'];
        //echo $customid;
        $custom_itemt = $customt->where("id=$customid")->find();
        $this->assign('company', $custom_itemt["company"]);
        $this->assign('cname', $custom_itemt["cname"]);
        //dump ($custom_itemt);
        $this->display();
    }

    public function addsave()
    {
        header("Content-Type:text/html; charset=utf-8");
        $custom = M('Appointment');
        $data = array('apptime' => $_POST['apptime'], 'content' => $_POST['content']);
        $id = $_GET['id'];
        $custom->where('rid='. $id)->setField($data); // 根据条件保存修改的数据
        $this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js">
        </script><script type="text/javascript">
        $(function(){top.Dialog.alert("成功提交",function(){window.parent.frmright.location.href="__APP__/Appointment";
        top.Dialog.close()})})</script>', 'utf-8');

    }

    public function delitem()
    {
        header("Content-Type:text/html; charset=utf-8");
        $custom = M('Appointment');
        $id = $_GET['id'];
        $custom->where('id=' . $id)->delete(); // 根据条件保存修改的数据
        $this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js">
        </script><script type="text/javascript">
        $(function(){top.Dialog.alert("成功提交",function(){window.parent.frmright.location.href="__APP__/Appointment";
        top.Dialog.close()})})</script>', 'utf-8');
    }
}

?>